package com.demo.controller;

import com.demo.domain.UserEntity;
import com.demo.service.virtual.HelloDaoInterface;
import com.demo.util.GENDER;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Date;

@RestController
public class HelloController {

    @Autowired
    private HelloDaoInterface helloDaoInterface;

    @RequestMapping("/hello")
    public String work() {
        String ret = new Date().toString() + ": Hello Maven!";
        System.out.println(ret);
        return ret;
    }

    @RequestMapping("/")
    public String index() {
        String ret = new Date().toString() + ": Hello World!";
        System.out.println(ret);
        return ret;
    }

    @RequestMapping("/user")
    public ArrayList<UserEntity> getUser() {
        ArrayList<UserEntity> users = new ArrayList<>();
        users.add(new UserEntity("Tim Duncan", 40, GENDER.MALE));
        users.add(new UserEntity("Manu Ginobili", 40, GENDER.MALE));
        users.add(new UserEntity("Tony Park", 38, GENDER.MALE));
        return users;
    }

    @RequestMapping("/getUser")
    public UserEntity getUserEntity(){
        return (helloDaoInterface.getUserEntityByName("Tony Park"));
    }

    @RequestMapping("/setUser")
    public String setUserEntity(){
        helloDaoInterface.save(new UserEntity("Tim Duncan", 40, GENDER.MALE));
        helloDaoInterface.save(new UserEntity("Manu Ginobili", 40, GENDER.MALE));
        helloDaoInterface.save(new UserEntity("Tony Park", 38, GENDER.MALE));

        return "success";
    }
}
